package com.example.rbac.service.impl;

import com.example.rbac.Exception.ResultErrorException;
import com.example.rbac.entity.Menu;
import com.example.rbac.entity.RoleMenu;
import com.example.rbac.mapper.MenuMapper;
import com.example.rbac.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/10/12.
 */
@Service
public class MenuServiceImpl extends CurdServiceImpl<MenuMapper, Menu> implements MenuService {

//    @Autowired
//    private MenuMapper menuMapper;

    @Override
    public List<String> findMenuByRoleId(List<String> list) {
        return repository.findMenuByRoleId(list);
    }

    @Override
    public List<Menu> findMenuByMenuId(List<String> list) {
        return repository.findMenuByMenuId(list);
    }

    @Override
    public List<Menu> findList() {
        return repository.findList();
    }

    @Override
    public Integer deleteMenuById(String id) {
        return repository.deleteMenuById(id);
    }

    @Override
    public List<Menu> findMenuByUserId(String id) {
        return repository.findMenuByUserId(id);
    }

    @Override
    public Integer insertByPermission(List<RoleMenu> roleMenus) {
        return repository.insertByPermission(roleMenus);
    }

    @Override
    public Integer updateByPermission(String roleId, List<RoleMenu> roleMenus) {
        return repository.updateByPermission(roleId,roleMenus);
    }

    @Override
    public List<Menu> findMenuListByRoleId(String id) {
        return repository.findMenuListByRoleId(id);
    }

    @Override
    public Menu getMenuByUrl(String url) {
        return repository.getMenuByUrl(url);
    }

    @Override
    public Integer updateBySort(List<Menu> list) throws ResultErrorException {
        try {
            if (list.size() == 0){
                throw new ResultErrorException("参数为空");
            }
            return repository.updateBySort(list);
        }catch (ResultErrorException e){
            throw e;
        }
    }
}
